Private Declare Function SelectPalette Lib "gdi32" (ByVal hdc As Long, ByVal hPalette As Long, ByVal bForceBackground As Long) As Long
Private Declare Function RealizePalette Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function CreateCompatibleBitmap Lib "gdi32" (ByVal hdc As Long, ByVal nWidth As Long, ByVal nHeight As Long) As Long
Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long
Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Private Declare Function GetDIBits Lib "gdi32" (ByVal aHDC As Long, ByVal hBitmap As Long, ByVal nStartScan As Long, ByVal nNumScans As Long, lpBits As Any, lpBI As BITMAPINFO, ByVal wUsage As Long) As Long
Private Declare Function StretchDIBits Lib "gdi32" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long, ByVal dx As Long, ByVal dy As Long, ByVal SrcX As Long, ByVal SrcY As Long, ByVal wSrcWidth As Long, ByVal wSrcHeight As Long, lpBits As Any, lpBitsInfo As BITMAPINFO, ByVal wUsage As Long, ByVal dwRop As Long) As Long
' API constants.
Private Const SRCCOPY = &HCC0020
Private Const BI_RGB = 0&
Private Const DIB_RGB_COLORS = 0
Private Const GDI_ERROR = &HFFFF
' Return a binary representation of the byte.
' This helper function is useful for understanding
' byte values.
Public Function BinaryByte(ByVal value As Byte) As String
Dim i As Integer
Dim txt As String
For i = 1 To 8
If value And 1 Then
txt = "1" & txt
Else
txt = "0" & txt
End If
value = value \ 2
Next i
BinaryByte = txt
End Function
' Find the closest color in the Colors array.
Public Function FindColorIndex(ByVal r As Integer, ByVal g As Integer, ByVal b As Integer, ByVal num_colors As Integer, Colors() As RGBQUAD) As Byte
Dim i As Integer
Dim best_i As Integer
Dim best_dist2 As Long
Dim dr As Long
Dim dg As Long
Dim db As Long
Dim dist2 As Long
best_i = 0
best_dist2 = CLng(3) * 256 * 256
For i = 0 To num_colors - 1
With Colors(i)
dr = r - .rgbRed
dg = g - .rgbGreen
db = b - .rgbBlue
End With
dist2 = dr * dr + dg * dg + db * db
If best_dist2 > dist2 Then
best_dist2 = dist2
best_i = i
End If
Next i
FindColorIndex = best_i
End Function
' Load the bits from this PictureBox with a color
' depth of 24 bits into a two-dimensional array of
' RGB values.
'
' Note that the pixels are flipped vertically in
' the DIB structure. This routine flips them
' so the upper left corner is at pixels(0, 0).
Public Sub GetDIBPixels24Bit(ByVal pic As PictureBox, ByRef bitmap_info As BITMAPINFO, ByRef pixels() As RGBTriplet)